# ~*~ coding: utf-8 ~*~

import time

from apps.common.dbbase import BaseModel
from apps.common.utils import generate_uuid
from apps.extensions import db

__all__ = ['Label']


class Label(BaseModel):
    __tablename__ = 'assets_label'

    SYSTEM_CATEGORY = "SYSTEM"
    USER_CATEGORY = "USER"

    id = db.Column(db.CHAR(36), default=generate_uuid, primary_key=True)
    name = db.Column(db.VARCHAR(128), unique=True)
    value = db.Column(db.VARCHAR(128))
    category = db.Column(db.VARCHAR(128), default=USER_CATEGORY)
    is_active = db.Column(db.BOOLEAN, default=1)
    comment = db.Column(db.TEXT, default='')

    # Other
    create_by = db.Column(db.VARCHAR(32), nullable=True)
    create_time = db.Column(db.INT, default=time.time)
    update_time = db.Column(db.INT, default=time.time, onupdate=time.time)

    def __str__(self):
        return "<Label: {}>".format(self.name)
